home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevrops.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.5 KB  |  196 lines

  1. /* Copyright (C) 1995, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevrops.c,v 1.3 2000/09/19 19:00:22 lpd Exp $ */
  20. /* RasterOp source device */
  21. #include "gx.h"
  22. #include "gserrors.h"
  23. #include "gxdcolor.h"
  24. #include "gxdevice.h"
  25. #include "gdevmrop.h"
  26.  
  27. /* GC procedures */
  28. private_st_device_rop_texture();
  29. private ENUM_PTRS_BEGIN(device_rop_texture_enum_ptrs) {
  30.     if (index < st_device_color_max_ptrs) {
  31.     gs_ptr_type_t ptype =
  32.         ENUM_SUPER_ELT(gx_device_rop_texture, st_device_color, texture, 0);
  33.  
  34.     if (ptype)
  35.         return ptype;
  36.     return ENUM_OBJ(NULL);    /* don't stop early */
  37.     }
  38.     ENUM_PREFIX(st_device_forward, st_device_color_max_ptrs);
  39. } ENUM_PTRS_END
  40. private RELOC_PTRS_BEGIN(device_rop_texture_reloc_ptrs) {
  41.     RELOC_PREFIX(st_device_forward);
  42.     RELOC_SUPER(gx_device_rop_texture, st_device_color, texture);
  43. } RELOC_PTRS_END
  44.  
  45. /* Device for providing source data for RasterOp. */
  46. private dev_proc_fill_rectangle(rop_texture_fill_rectangle);
  47. private dev_proc_copy_mono(rop_texture_copy_mono);
  48. private dev_proc_copy_color(rop_texture_copy_color);
  49.  
  50. /* The device descriptor. */
  51. private const gx_device_rop_texture gs_rop_texture_device = {
  52.     std_device_std_body(gx_device_rop_texture, 0, "rop source",
  53.             0, 0, 1, 1),
  54.     {NULL,                /* open_device */
  55.      gx_forward_get_initial_matrix,
  56.      NULL,                /* default_sync_output */
  57.      NULL,                /* output_page */
  58.      NULL,                /* close_device */
  59.      gx_forward_map_rgb_color,
  60.      gx_forward_map_color_rgb,
  61.      rop_texture_fill_rectangle,
  62.      NULL,                /* tile_rectangle */
  63.      rop_texture_copy_mono,
  64.      rop_texture_copy_color,
  65.      NULL,                /* draw_line */
  66.      NULL,                /* get_bits */
  67.      gx_forward_get_params,
  68.      gx_forward_put_params,
  69.      gx_forward_map_cmyk_color,
  70.      gx_forward_get_xfont_procs,
  71.      gx_forward_get_xfont_device,
  72.      gx_forward_map_rgb_alpha_color,
  73.      gx_forward_get_page_device,
  74.      NULL,                /* get_alpha_bits (no alpha) */
  75.      gx_no_copy_alpha,        /* shouldn't be called */
  76.      gx_forward_get_band,
  77.      gx_no_copy_rop,        /* shouldn't be called */
  78.      NULL,                /* fill_path */
  79.      NULL,                /* stroke_path */
  80.      NULL,                /* fill_mask */
  81.      NULL,                /* fill_trapezoid */
  82.      NULL,                /* fill_parallelogram */
  83.      NULL,                /* fill_triangle */
  84.      NULL,                /* draw_thin_line */
  85.      NULL,                /* begin_image */
  86.      NULL,                /* image_data */
  87.      NULL,                /* end_image */
  88.      NULL,                /* strip_tile_rectangle */
  89.      NULL,                /* strip_copy_rop */
  90.      gx_forward_get_clipping_box,
  91.      NULL,                /* begin_typed_image */
  92.      NULL,                /* get_bits_rectangle */
  93.      gx_forward_map_color_rgb_alpha,
  94.      NULL,                /* create_compositor */
  95.      gx_forward_get_hardware_params,
  96.      NULL,                /* text_begin */
  97.      NULL                /* finish_copydevice */
  98.     },
  99.     0,                /* target */
  100.     lop_default            /* log_op */
  101.     /* */                /* texture */
  102. };
  103.  
  104. /* Create a RasterOp source device. */
  105. int
  106. gx_alloc_rop_texture_device(gx_device_rop_texture ** prsdev, gs_memory_t * mem,
  107.                 client_name_t cname)
  108. {
  109.     *prsdev = gs_alloc_struct(mem, gx_device_rop_texture,
  110.                   &st_device_rop_texture, cname);
  111.     return (*prsdev == 0 ? gs_note_error(gs_error_VMerror) : 0);
  112. }
  113.  
  114. /* Initialize a RasterOp source device. */
  115. void
  116. gx_make_rop_texture_device(gx_device_rop_texture * dev, gx_device * target,
  117.          gs_logical_operation_t log_op, const gx_device_color * texture)
  118. {
  119.     gx_device_init((gx_device *) dev,
  120.            (const gx_device *)&gs_rop_texture_device,
  121.            NULL, true);
  122.     gx_device_set_target((gx_device_forward *)dev, target);
  123.     /* Drawing operations are defaulted, non-drawing are forwarded. */
  124.     gx_device_fill_in_procs((gx_device *) dev);
  125.     gx_device_copy_params((gx_device *)dev, target);
  126.     dev->log_op = log_op;
  127.     dev->texture = *texture;
  128. }
  129.  
  130. /* Fill a rectangle */
  131. private int
  132. rop_texture_fill_rectangle(gx_device * dev, int x, int y, int w, int h,
  133.                gx_color_index color)
  134. {
  135.     gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
  136.     gx_rop_source_t source;
  137.  
  138.     source.sdata = NULL;
  139.     source.sourcex = 0;
  140.     source.sraster = 0;
  141.     source.id = gx_no_bitmap_id;
  142.     source.scolors[0] = source.scolors[1] = color;
  143.     source.use_scolors = true;
  144.     return gx_device_color_fill_rectangle(&rtdev->texture,
  145.                       x, y, w, h, rtdev->target,
  146.                       rtdev->log_op, &source);
  147. }
  148.  
  149. /* Copy a monochrome rectangle */
  150. private int
  151. rop_texture_copy_mono(gx_device * dev,
  152.         const byte * data, int sourcex, int raster, gx_bitmap_id id,
  153.               int x, int y, int w, int h,
  154.               gx_color_index color0, gx_color_index color1)
  155. {
  156.     gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
  157.     gx_rop_source_t source;
  158.     gs_logical_operation_t lop = rtdev->log_op;
  159.  
  160.     source.sdata = data;
  161.     source.sourcex = sourcex;
  162.     source.sraster = raster;
  163.     source.id = id;
  164.     source.scolors[0] = color0;
  165.     source.scolors[1] = color1;
  166.     source.use_scolors = true;
  167.     /* Adjust the logical operation per transparent colors. */
  168.     if (color0 == gx_no_color_index)
  169.     lop = rop3_use_D_when_S_0(lop);
  170.     else if (color1 == gx_no_color_index)
  171.     lop = rop3_use_D_when_S_1(lop);
  172.     return gx_device_color_fill_rectangle(&rtdev->texture,
  173.                       x, y, w, h, rtdev->target,
  174.                       lop, &source);
  175. }
  176.  
  177. /* Copy a color rectangle */
  178. private int
  179. rop_texture_copy_color(gx_device * dev,
  180.         const byte * data, int sourcex, int raster, gx_bitmap_id id,
  181.                int x, int y, int w, int h)
  182. {
  183.     gx_device_rop_texture *const rtdev = (gx_device_rop_texture *)dev;
  184.     gx_rop_source_t source;
  185.  
  186.     source.sdata = data;
  187.     source.sourcex = sourcex;
  188.     source.sraster = raster;
  189.     source.id = id;
  190.     source.scolors[0] = source.scolors[1] = gx_no_color_index;
  191.     source.use_scolors = false;
  192.     return gx_device_color_fill_rectangle(&rtdev->texture,
  193.                       x, y, w, h, rtdev->target,
  194.                       rtdev->log_op, &source);
  195. }
  196.